{% include "header.html" %}

<div class="container">
    <div class="box box-warning">
        <div class="box-header">
            <h4 class="box-title"><span class="fa fa-plus-circle"></span>用户注册</h4>
        </div>
        <div class="box-body">
            <form method="post" class="form-horizontal">
                <div class="form-group">
                    <label for="username" class="control-label col-lg-2 col-sm-2 col-xs-4">账号</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_id" id="username" class="form-control" placeholder="请输入账号" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="control-label col-lg-2 col-sm-2 col-xs-4">密码</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_pass" id="password" class="form-control" placeholder="请输入密码" type="password" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="password2" class="control-label col-lg-2 col-sm-2 col-xs-4">确认密码</label>
                    <div class="col-lg-10 col-sm-10">
                        <input id="password2" class="form-control" placeholder="再次输入密码" type="password" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="real_name" class="control-label col-lg-2 col-sm-2 col-xs-4">姓名</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_name" id="real_name" class="form-control" placeholder="李某某" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="class" class="control-label col-lg-2 col-sm-2 col-xs-4">专业班级</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_class" id="class" class="form-control" placeholder="专业班级（计科1604）" required>
                    </div>
                </div>
                <div class="form-group">
                    <label for="tel" class="control-label col-lg-2 col-sm-2 col-xs-4">手机号</label>
                    <div class="col-lg-10 col-sm-10">
                        <input name="stu_tel" id="tel" class="form-control" placeholder="手机号（找回密码的凭证）" maxlength="11" required>
                    </div>
                </div>
                <div class="form-group">
                    <label style="padding-top: 8px;" for="code" class="control-label text-danger col-lg-2 col-sm-2 col-xs-5">注册邀请码</label>
                    <div class="col-lg-10 col-sm-10 col-xs-7">
                        <input name="code" id="code" class="form-control" placeholder="请输入邀请码" type="text" required>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-12" style="margin-top: 5px;">
                        <button type="submit" class="btn btn-warning btn-block">注册</button>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-6 col-xs-6">
                        <a href="/about" class="text-success"><i class="fa fa-info"></i> 关于我们</a>
                    </div>
                    <div class="col-lg-6 col-xs-6 text-right">
                        <a href="/login" class="text-black">马上登录 <span class="fa fa-sign-in"></span></a>
                    </div>
                </div>
            </form>
            {% include "sign.html" %}
        </div>
    </div>
</div>

<script>
    $('form').submit(function (e) {
        e.preventDefault();
{#        console.log($(this).serialize())#}
        var username = $('#username').val().trim();
        var p1 = $('#password').val().trim();
        var p2 = $('#password2').val().trim();
        var name = $('#real_name').val().trim();
        var tel = $('#tel').val().trim();
        var clz = $('#class').val().trim();
        if (/\W/.test(username)) {
            alert('用户名不能存在中文！');
        } else if (/\W/.test(p1)) {
            alert("密码不能存在中文！");
        } else if (p1.length < 6) {
            alert("密码不能小于6位！");
        } else if (p1 !== p2) {
            alert("两次密码不相同！");
        } else if (!/^[\u4e00-\u9fa5]+$/.test(name)) {
            alert("无法识别你的名字、、、");
        } else if (!/^[\u4e00-\u9fa5]{2}[1-2][5-9]0[1-6]$/.test(clz)) {
            alert("班级格式不正确！");
        } else if (!/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(tel)) {
            alert("电话号码格式错误！");
        } else {
            $.post('/register', $(this).serialize(), function (data) {
                if (data.status) {
                    alert('SUCCESS: 注册成功！即将跳转登录');
                    location.href = '/login'
                } else {
                    alert('ERROR: 注册失败！'+data.msg);
                }
            });
        }
    });
</script>

</body>
</html>